<template>
    <div class="pie">
      <div :id="'pie' + cageId" :style="styles"></div>
    </div>
</template>

<script>
import echarts from 'echarts';
export default {
  data () {
    return {
      cageId: parseInt(Math.random() * 100000)
    };
  },
  mounted () {
    this.drawLine();
  },
  props: {
    // 样式
    styles: Object,
    // 参数数据
    paramsData: Array,
    // 提示数据
    xData: Array,
    // 标题
    title: String
  },
  methods: {
    drawLine () {
      let that = this;
      console.log(that.xData);
      // 基于准备好的dom，初始化echarts实例
      let myChart = echarts.init(document.getElementById('pie' + that.cageId));
      // 绘制图表
      myChart.setOption({
        title: {
          text: that.title,
          x: 'center'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        series: [
          {
            name: '访问来源',
            type: 'pie',
            radius: '55%',
            center: ['50%', '60%'],
            data: that.paramsData,
            itemStyle: {
              emphasis: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      });
    }
  }
};
</script>


<style lang="stylus" scoped>

</style>
